﻿using UnityEngine;
using System.Collections;
using Dict;
using Dict.DataModel;
using System.Collections.Generic;

namespace UI
{
    public class FormationItem : MonoBehaviour
    {

        public GameObject formationItemModel;

        public GameObject EffectTxt;//特效暂时没用上

        public GameObject postionSprite;

        public GameObject topLight;

        private bool isShowLight;

        public float currentAlpha;

        private int alphaFlag;

        

        /// <summary>
        /// 高亮显示
        /// </summary>
        public void ShowLight()
        {
            isShowLight = true;
            topLight.SetActive(true);
        }
        /// <summary>
        /// 取消高亮
        /// </summary>
        public void HideLight()
        {
            isShowLight = false;
            topLight.SetActive(false);
        }
        /// <summary>
        /// 初始化上阵的英雄
        /// </summary>
        /// <param name="formationId"></param>
        /// <param name="modelPostion"></param>
        public void Init(int formationId, string modelPostion)
        {
            isShowLight = false;
            currentAlpha = 0f;
            alphaFlag = 0;
            topLight.SetActive(false);
            //this.formationPanel = panel;

            
            formationItemModel.GetComponent<FormationItemModel>().Init(formationId, modelPostion);
            
            postionSprite.GetComponent<UISprite>().spriteName = "p" + formationId;
            //foreach (var item in prop)
            //{
            //    if (item.FPId == formationId)
            //    {
            //        if (item.PropId == (int)Dict.Enum.DictProp.Attack)
            //        {
            //            ///临时
            //            EffectTxt.GetComponent<UISprite>().spriteName = "attack";
            //            //EffectTxt.GetComponent<UISprite>().MakePixelPerfect();
            //        }
            //        else if (item.PropId == (int)Dict.Enum.DictProp.Defense)
            //        {

            //            ///临时
            //            EffectTxt.GetComponent<UISprite>().spriteName = "defese";
            //        }
            //        else if (item.PropId == (int)Dict.Enum.DictProp.HitAdd)
            //        {
            //            EffectTxt.GetComponent<UISprite>().spriteName = "hit";
            //        }
            //        else if (item.PropId == (int)Dict.Enum.DictProp.TreatEffectAdd)
            //        {
            //            EffectTxt.GetComponent<UISprite>().spriteName = "zhiliao";
            //        }
            //        EffectTxt.GetComponent<UISprite>().MakePixelPerfect();
            //        break;
            //    }
            //}
        }

        void Update()
        {
            if (isShowLight)
            {
                if (alphaFlag == 0)
                {
                    currentAlpha += 0.03f;
                }
                else
                {
                    currentAlpha -= 0.03f;
                }
                if (currentAlpha < 0)
                {
                    alphaFlag = 0;
                }
                else if (currentAlpha > 1)
                {
                    alphaFlag = 1;
                }
                topLight.GetComponent<UISprite>().alpha = currentAlpha;

            }
        }
    }

}